x86/vpmu: add get/put_vpmu() and VPMU_AVAILABLE
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 1 Mar 2017 16:50:48 +0000 (17:50 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 1 Mar 2017 16:50:48 +0000 (17:50 +0100)
commit4a970125d1f538431b2f0dc7802db59258f17725
tree53558954e611ef24e18f721a1127de8c79828445
parentd621c6d61a66e873377ace09452c680007cb2d85
x86/vpmu: add get/put_vpmu() and VPMU_AVAILABLE

vpmu_enabled() (used by hvm/pv_cpuid() to properly report 0xa leaf
for Intel processors) is based on the value of VPMU_CONTEXT_ALLOCATED
bit. This is problematic:
* For HVM guests VPMU context is allocated lazily, during the first
  access to VPMU MSRs. Since the leaf is typically queried before guest
  attempts to read or write the MSRs it is likely that CPUID will report
  no PMU support
* For PV guests the context is allocated eagerly but only in responce to
  guest's XENPMU_init hypercall. There is a chance that the guest will
  try to read CPUID before making this hypercall.

This patch introduces VPMU_AVAILABLE flag which is set (subject to vpmu_mode
constraints) during VCPU initialization for both PV and HVM guests. Since
this flag is expected to be managed together with vpmu_count, get/put_vpmu()
are added to simplify code.

vpmu_enabled() (renamed to vpmu_available()) can now use this new flag.

(As a side affect this patch also fixes a race in pvpmu_init() where we
increment vcpu_count in vpmu_initialise() after checking vpmu_mode)

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/vpmu.c
xen/arch/x86/cpuid.c
xen/arch/x86/domain.c
xen/arch/x86/hvm/svm/svm.c
xen/arch/x86/hvm/vmx/vmx.c
xen/include/asm-x86/vpmu.h